package co.gov.medellin.ssti.sub.service;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.NamingException;

import co.gov.medellin.ssti.sub.common.ConexionFactory;
import co.gov.medellin.ssti.sub.model.dao.DAOFactory;
import co.gov.medellin.ssti.sub.model.dao.IRestriccionDAO;
import co.gov.medellin.ssti.sub.model.dao.exception.DAOException;
import co.gov.medellin.ssti.sub.model.vo.RestriccionVO;

public class RestriccionService {
	/**
	 * 
	 * @param CodigoAtri
	 * @param CodRest
	 * @param Valor
	 * @param TipoDato
	 * @return
	 * @throws DAOException
	 */
	public String[] validarRestriccion(String CodigoAtri, String CodRest,
			String Valor, String TipoDato) throws DAOException {
		IRestriccionDAO restriccionDAO = null;
		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			restriccionDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getRestriccionDAO(con);
			return restriccionDAO.validarRestriccion(CodigoAtri, CodRest,
					Valor, TipoDato);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (restriccionDAO != null) {
				if (!restriccionDAO.isConnClosed()) {
					restriccionDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param CodRest
	 * @return
	 * @throws DAOException
	 */
	public RestriccionVO findRestriccion(String CodRest) throws DAOException {
		IRestriccionDAO restriccionDAO = null;
		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			restriccionDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getRestriccionDAO(con);
			return restriccionDAO.findRestriccion(CodRest);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (restriccionDAO != null) {
				if (!restriccionDAO.isConnClosed()) {
					restriccionDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param strCodRest
	 * @param Arr
	 * @return
	 * @throws DAOException
	 */
	public int modificarRestriccion(String strCodRest, String Arr[])
			throws DAOException {
		IRestriccionDAO restriccionDAO = null;
		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			restriccionDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getRestriccionDAO(con);
			return restriccionDAO.modificarRestriccion(strCodRest, Arr);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (restriccionDAO != null) {
				if (!restriccionDAO.isConnClosed()) {
					restriccionDAO.close();
				}
			}
		}
	}
}
